import { datas } from './fields.js'
let that
// 串口监听
export default {
	data() {
		return {
			...datas,
			numList: [
				{ name: '提交审批', desc: '提交审批' },
				{ name: '审批中' },
				{ name: '审批通过' },
			],
			current: 1,
			orderInfo: {},
			reason: '',
			imagePath: ''
		}
	},
	computed: {},
	onShow() {
		this.orderInfo = uni.getStorageSync("approveAdminInfo")
		console.info(this.orderInfo)
	},
	created() {
		that = this
	},
	onReady() {},
	onLoad(options) {
		this.orderInfo = uni.getStorageSync("approveAdminInfo")
	},
	methods: {
		bindTextAreaBlur(e) {
			this.reason = e.detail.value
		},
		changeMenu(e) {
			that.current = e
		},
		clearInput(e) {
			this.reason = e.detail.value
		},
		gotoInfo(item) {
			that.$common.navigateTo('/pages/audit/details/index')
		},
		chooseImages() {
			let _this = this
			uni.chooseImage({
				count: 1, // 默认9
				sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
				success: (res) => {
					_this.uploadImages(res)
				}
			});
		},
		uploadImages(file) {
			let _this = this
			uni.uploadFile({
				url: '/api/h5/upload',
				filePath: file.tempFilePaths[0] || '',
				name: 'file',
				formData: {},
				headers: { 'Content-Type': 'multipart/form-data' },
				success: (uploadFileRes) => {
					console.log(uploadFileRes)
					let jsonDes = JSON.parse(uploadFileRes.data)
					if (jsonDes && jsonDes.code == 200) {
						_this.imagePath = jsonDes.data
					} else {
						uni.showToast({
							title: '上传失败',
							icon: 'fail',
							duration: 2000
						});
					}
				},
				fail: (err) => {
					uni.showToast({
						title: '图片上传接口调用失败',
						icon: 'fail',
						duration: 2000
					});
				}
			})
		},
		subInfo(state = 0) {
			let datas = {
				"userId": uni.getStorageSync('userId'),
				"flag": state,
				"orderId": this.orderInfo.id,
				"reject": this.reason
			}
			
			uni.request({
				url: '/api/h5/deviceApplyExamine',
				method: "POST",
				header: {},
				data: datas,
				success: (res) => {
					if (res.data.code == 200) {
						
						uni.showToast({
							title: '操作成功',//标题 必填
							icon: 'none',//图标
						    mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false
						    duration: '1500',//提示的延迟时间，单位毫秒，默认：1500
						    success: '',//接口调用成功的回调函数	
						    fail: '',//接口调用失败的回调函数	
						    complete: function(res){},//接口调用结束的回调函数（调用成功、失败都会执行）
						});
						setTimeout(()=>{
							uni.navigateBack()
						},1500)
					
					} else {
						uni.showToast({
							title: '操作失败，请联系管理员',//标题 必填
							icon: 'none',//图标
						    mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false
						    duration: '1000',//提示的延迟时间，单位毫秒，默认：1500
						    success: '',//接口调用成功的回调函数	
						    fail: '',//接口调用失败的回调函数	
						    complete: function(res){},//接口调用结束的回调函数（调用成功、失败都会执行）
						});
						setTimeout(()=>{
							uni.navigateBack()
						},1500)
						
					}
				},
				fail: (err) => {
					console.error(err);
				}
			});
			

		}
	}
}